#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char const *argv[])
{
        if(argc != 2){
                printf("./a.out fifoname\n");
                return -1;
        }

        //当前目录有一个myfifo文件
        //打开fifo文件
        int fd = open(argv[1], O_RDONLY);

        //读
        char buf[256];
        int ret;
        while (1){
                memset(buf, 0, sizeof(buf));
                ret = read(fd, buf, sizeof(buf));
                if(ret > 0){
                        printf("read:%s\n", buf);
                }
        }
        close(fd);
        return 0;
}
